﻿using System;
using System.Collections.Generic;

using Layers;

namespace HoldemGame
{
    public class GameTable : GameObject
    {
        private CardSet _boardCards;

        //public CardSet Cards { get { return _cards; } }

        public GameSeats Seats = new GameSeats();

        /*public CardSet PocketCards(int playerIndex)
        {
            return _cards.GetCardSet(2 * playerIndex, 2, false);
        }*/

        public void ResetCards()
        {
            _boardCards.SetAll(Card.Invalid);
            foreach (GameSeat seat in Seats)
            {
                if (null != seat.Player)
                    seat.Player.PocketCards.SetAll(Card.Invalid);
            }
        }
        public CardSet BoardCards()
        {
            return _boardCards;// cards.GetCardSet(2 * Game.Players.Count, 5, false);
        }

        public CardSet VisibleBoardCards()
        {
            return _boardCards.GetCardSet(0,VisibleBoardCardsCount, false);//_cards.GetCardSet(2 * Game.Players.Count, 
        }

        public CardSet FlopCards()
        {
            //return _cards.GetCardSet(2 * Game.Players.Count, 3, false);
            return _boardCards.GetCardSet(0, 3, false);
        }

        public CardSet TurnCards()
        {
            //return _cards.GetCardSet(2 * Game.Players.Count + 3, 1, false);
            return _boardCards.GetCardSet(3, 1, false);
        }

        public CardSet RiverCards()
        {
            //return _cards.GetCardSet(2 * Game.Players.Count + 4, 1, false);
            return _boardCards.GetCardSet(4, 1, false);
        }

        public int FindCard(Card card)
        {
            /*int i = _cards.IndexOf(card);
            if (i<0)
                return GameObject.INVISIBLE;
            if (i < 2 * Game.Players.Count)
                return i / 2;
            if (i - 2 * Game.Players.Count < VisibleBoardCardsCount)
                return GameObject.BOARD;
            return GameObject.INVISIBLE;*/
            return GameObject.INVISIBLE;//TODO
        }

        public int VisibleBoardCardsCount 
        { 
            get 
            {
                //if (Game.ShowAllCards)
                  //  return 5;

                switch(Game.Stage)
                {
                    case HoldemStage.Start: return 0;
                    case HoldemStage.PreFlop: return 0;
                    case HoldemStage.PostFlop: return 3;
                    case HoldemStage.PostTurn: return 4;
                    case HoldemStage.PostRiver: return 5;
                    case HoldemStage.Showdown: return 5;
                }
                throw new InvalidOperationException();
            } 
        }

        public GameTable(Game game) : base(game)
        {
            _boardCards = new CardSet(5);
        }
    }
}